package com.snowyee.yudada.controller;

import com.snowyee.yudada.common.BaseResponse;
import com.snowyee.yudada.common.ErrorCode;
import com.snowyee.yudada.common.ResultUtils;
import com.snowyee.yudada.exception.ThrowUtils;
import com.snowyee.yudada.mapper.UserAnswerMapper;
import com.snowyee.yudada.model.dto.statistic.AppAnswerCountDTO;
import com.snowyee.yudada.model.dto.statistic.AppAnswerResultCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * App统计分析接口
 *
 *  
 */
@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class AppStatisticController {

    @Resource
    private UserAnswerMapper userAnswerMapper;
    /**
     * 统计某个App下用户的答题情况
     */
    @GetMapping("/answer_count")
    public BaseResponse<List<AppAnswerCountDTO>> getAppAnswerCount(){
        return ResultUtils.success(userAnswerMapper.doAppAnswerCount());
    }

    /**
     * 统计某个答案下用户的答题情况
     */
    @GetMapping("answer_result_count")
    public BaseResponse<List<AppAnswerResultCountDTO>> getAppAnswerResultCount(Long appId){
        // 判断一下参数异常
        ThrowUtils.throwIf(appId == null || appId <= 0, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerMapper.doAppAnswerResultCount(appId));
    }

}